﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TipCalc.Business;

namespace TipCalc.Test.Unit
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class BillTest
    {
        public BillTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void Bill_AmountSetToNegative_ThrowsArgumentOutOfRangeException()
        {
            //  Arrange
            Bill bill = new Bill();

            //  Act
            bill.BillAmount = (decimal)-1.23;

            //  Assert - Nothing to assert.  Test checks for thrown exception.
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void Bill_TipPercentageSetToNegative_ThrowsArgumentOutOfRangeException()
        {
            //  Arrange
            Bill bill = new Bill();

            //  Act
            bill.TipPercentage = (decimal)-0.01;

            //  Assert - Nothing to assert.  Test checks for thrown exception.
        }

        [TestMethod]
        public void Bill_PositiveAmountAndTipPercentage_TipAmountCalculatesCorrectly()
        {
            //  Arrange
            Bill bill = new Bill() { BillAmount = 50, TipPercentage = 20 };
            decimal expectedTotal = 10.00m;
            decimal actualTotal;

            //  Act
            actualTotal = bill.TipAmount;

            //  Assert
            Assert.AreEqual(expectedTotal, actualTotal);
        }

        [TestMethod]
        public void Bill_PositiveAmountAndTipPercentage_TipAmountRoundsDownCorrectly()
        {
            //  Arrange
            Bill bill = new Bill() { BillAmount = 50.02m, TipPercentage = 20.00m };
            decimal expectedTotal = 10.00m;
            decimal actualTotal;

            //  Act
            actualTotal = bill.TipAmount;

            //  Assert
            Assert.AreEqual(expectedTotal, actualTotal);
        }

        [TestMethod]
        public void Bill_PositiveAmountAndTipPercentage_TipAmountRoundsUpCorrectly()
        {
            //  Arrange
            //  Use these numbers to expose whether or not banker's rounding is being used (MidpointRounding.ToEven).
            //  We should be using MidpointRounding.AwayFromZero.
            Bill bill = new Bill() { BillAmount = 0.25m, TipPercentage = 10.00m };
            decimal expectedTotal = 0.03m;
            decimal actualTotal;

            //  Act
            actualTotal = bill.TipAmount;

            //  Assert
            Assert.AreEqual(expectedTotal, actualTotal);
        }
    }
}
